const express = require('express')
const { ApolloServer, gql } = require('apollo-server-express')

const typeDefs = gql`
  #类型后面加!号,返回的时候该数据不能为空
  type Student {
    sname: String!
    age: Int
  }
  type Query {
    hello: String
    stu: Student
  }
`

const resolvers = {
  Query: {
    hello: () => 'Hello world!111',
    stu: () => {
      return {
        sname: '李四',
        age: 121
      }
    }
  }
}

const server = new ApolloServer({ typeDefs, resolvers })

const app = express()
server.applyMiddleware({ app })

app.listen({ port: 4000 }, () => console.log('Now browse to http://localhost:4000' + server.graphqlPath))
